package test06;

/**
 * Created by tianxiadiyishuai on 2017/10/15.
 */
public class Triangle {
    //属性:三个边，以及周长、面积,Boolean型
    double side1,side2,side3,p,length,area;
    boolean z;
    //行为:返回周长、面积以及修改三个边
    public Triangle(double a,double b,double c){
        this.side1=a;
        this.side2=b;
        this.side3=c;
        if ((a+b>c&a+c>b&b+c>a)&(a-b<c&a-c<b&b-c<a))
            z=true;
        else
            z=false;
    }
    //构造函数
    public double Tarea() {
        if (z) {
            p = (side1 + side2 + side3) / 2;
            area = Math.sqrt(p * (p - side1) * (p - side2) * (p - side3));
            return area;
        } else {
            System.out.println("不是三角形无法运算");
        }
        return 0;
    }
    public double Tlength() {
        if (z) {
            length = side1 + side2 + side3;
            return length;
        } else {
            System.out.println("不是三角形无法运算");
        }
        return 0;
    }
    //main函数
    public static void main(String[] args) {
        Triangle Tarea1=new Triangle(5,4,5);
        System.out.println("面积是："+Tarea1.Tarea());
        Triangle Tlength1=new Triangle(5,4,5);
        System.out.println("周长是："+Tlength1.Tlength());
    }

}
